<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of project
 *
 * @author nstevens
 */
require_once 'controller/commonController.php';
require_once 'model/projectModelClass.php';
require_once 'view/projectViewClass.php';
require_once 'utility.php';

class projectControllerClass extends commonController {

    public function __construct($model) {
        $this->model = $model;
    }

    //actions*******************************************************************
    //****VIEWS*****************************************************************
    
    function viewProjectDetails() {
        $this->model->init($_GET['projectId'], 2);
        if (isset($_GET['activeDiv'])) {
            $activeDiv = $_GET['activeDiv'];
        } else {
            $activeDiv = NULL;
        }
        $this->model->string = $this->model->getProjectDetailsPage($this->model, $activeDiv);
    }
    
    function viewMyProjects() {
        $curUser = $_SESSION['username'];
        $personID = getPersonIDFromUsername($curUser);
        $projectObjArray = $this->model->getProjectsThatThisPersonIsRelatedTo($personID);
        $this->model->string = "";
        $this->model->string .= $this->model->getBasicHeader("View Projects");
        $this->model->string .= $this->model->getProjectSummaryTable($projectObjArray);
        $this->model->string .= '<br><br> '. getWebmasterFeedbackForm();
    }

    function viewProjectRebaselinePage(){
        //echo 'hi';
        $this->model->init($_GET['projectId'], 2);
        $this->model->string .= $this->model->getProjectRebaselinePage();
    }
    function viewProjects() {
        //$projectObjArray = $this->model->getAllProjects(1);
        $projectObjArray = $this->model->getApprovedProjectsObjects();
        $this->model->string = "";
        $this->model->string .= $this->model->getBasicHeader("View Projects");
        $this->model->string .= $this->model->getProjectSummaryTable($projectObjArray);
    }

    function viewProposals() {
        $projectObjArray = $this->model->getProposals();
        $this->model->string = "";
        $this->model->string .= $this->model->getBasicHeader("View Proposals");
        $this->model->string .= $this->model->getProjectSummaryTable($projectObjArray);
    }

    function viewProposalSummary() {
        echo 'view proposal summary';
    }

    function viewNonLaborDetails() {
        $this->model->init($_GET['projectId'], 2);
        $this->model->string = $this->model->getNonLaborDetailsPage();
    }

    function viewContractDetails() {
        $this->model->init($_GET['projectId'], 2);
        $this->model->string = $this->model->getContractDetailsPage();
    }

    //****FORMS*****************************************************************
    function proposeProjectRequest() {
        if (isset($_POST['fyDropdown'])) {
            $fy = $_POST['fyDropdown'];
            $this->model->string = $this->model->getproposeProjectRequestPage($fy);
        } else {
            $this->model->string = $this->model->getproposeProjectRequestSelectYearPage();
        }
    }

    function proposeNewTaskRequest() {
        $this->model->init($_POST['projectID'], 2);
        $this->model->string = $this->model->getNewTaskPage();
    }

    function proposeNewContractRequest() {
        $this->model->init($_POST['projectID'], 1);
        $this->model->string = $this->model->getNewContractPage();
    }

    function proposeNewNonLaborRequest() {
        $this->model->init($_POST['projectID'], 1);
        $this->model->string = $this->model->getNewNonLaborPage();
    }

    function editExistingProposal() {
        $this->model->init($_POST['projectID'], 1);
        $this->model->string = $this->model->getEditProjectPage();
    }

    function editExistingNonLabor() {
        $this->model->init($_POST['projectID'], 2);
        $this->model->string = $this->model->getEditNonLaborPage();
    }

    function editExistingContract() {
        $this->model->init($_POST['projectID'], 1);
        $this->model->string = $this->model->getEditContractPage();
    }

    function viewExistingReport() {
        $this->model->init($_POST['projectID'], 1);
        $this->model->string = $this->model->getEditExistingReportPage();
    }

    //****PROCESSING************************************************************
    function processExistingProjectRequest() {
        //echo $_POST['submit'];
        //return;
        if (isset($_POST['submit'])) {
            if (strcmp("Edit Expense", $_POST['submit']) === 0) {
                $this->editExistingNonLabor();
            } else if (strcmp("Delete Expense", $_POST['submit']) === 0) {
                $this->processDeleteExpense();
            } else if (strcmp("Save Expense", $_POST['submit']) === 0) {
                $this->processExistingNonLabor();
            } else if (strcmp("Edit Contract", $_POST['submit']) === 0) {
                $this->editExistingContract();
            } else if (strcmp("Delete Contract", $_POST['submit']) === 0) {
                $this->processDeleteContract();
            } else if (strcmp("Save Contract", $_POST['submit']) === 0) {
                $this->processExistingContract();
            } else if (strcmp("Activate", $_POST['submit']) === 0) {
                $this->processActivateTask();
            } else if (strcmp("Edit Project", $_POST['submit']) === 0) {
                $this->editExistingProposal();
            } else if (strcmp("Add Notes", $_POST['submit']) === 0) {
                $this->processAddNotesRequest();
            } else if (strcmp("Edit Report", $_POST['submit']) === 0 || strcmp("View Report", $_POST['submit'])) {
                $this->viewExistingReport();
            } else if (strcmp("New Report", $_POST['submit']) === 0) {
                $this->viewExistingReport();
            } else if (strcmp("Submit Report", $_POST['submit']) === 0) {
                $this->processSubmitReportRequest();
            } else if (strcmp("Upload Report", $_POST['submit']) === 0) {
                $this->processUploadReportRequest();
            }else {
                $this->processChangeTaskStatus();
            }
        }
    }

    function processRebaselineSubmitDecision(){
        $url = $this->model->processRebaselineSubmitDecisionRequest();
        if ($url) {
            header($url);
        } else {
            echo "error uploading";
        }
    }
    
    function processRebaselineSubmit(){
        $url = $this->model->processRebaselineSubmitRequest();
        if ($url) {
            header($url);
        } else {
            echo "error uploading";
        }
    }
    function processUploadReportRequest() {
        //print_r($_POST);
        //return;
        $url = $this->model->processUploadReport();
        if ($url) {
            header($url);
        } else {
            echo "error uploading";
        }
    }
    
    function processSubmitReportRequest() {
        $url = $this->model->processSubmitReport();
        if ($url) {
            header($url);
        } else {
            echo "error changing status";
        }
    }

    function processChangeStatusRequest() {
        //request rebaseline button
        $url = $this->model->processChangeStatus();
        if ($url) {
            header($url);
        } else {
            echo "error changing status";
        }
    }

    function processNewProposalSubmit() {
        $url = $this->model->processNewProposalSubmitRequest();
        if ($url) {
            header($url);
        } else {
            echo "error processing new proposal";
        }
    }

    function processNewContract() {
        $this->model->init($_POST['projectID'], 1);
        $url = $this->model->processNewContractRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error processing new labor";
        }
    }

    function processExistingContract() {
        $this->model->init($_POST['projectID'], 1);
        $url = $this->model->processExistingContractRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error processing existing labor";
        }
    }

    function processNewNonLabor() {
        $this->model->init($_GET['projectId'], 1);
        $url = $this->model->processNewNonLaborRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error processing new labor";
        }
    }

    function processExistingNonLabor() {
        $this->model->init($_GET['projectId'], 1);
        $url = $this->model->processExistingNonLaborRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error processing existing labor";
        }
    }

    function processDeleteExpense() {
        $this->model->init($_POST['projectID'], 1);
        $url = $this->model->processDeleteNonLaborRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error deleting existing labor";
        }
    }

    function processDeleteContract() {
        $this->model->init($_POST['projectID'], 1);
        $url = $this->model->processDeleteContractRequest();
        if ($url) {
            echo header($url);
        } else {
            echo "Error deleting existing contract";
        }
    }
   
    public function processRebaselineDecision(){
        $url = $this->model->processRebaselineDecisionRequest();
        if ($url) {
            header($url);
        } else {
            echo "error";
        }
    }
    //OTHER STUFF***************************************************************
}

?>
